/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.app.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *
 * @author Administrator
 */
@Entity
@Table(name = "product")
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)    
    
    @Column(name = "id")
    private Integer id;
    
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    
    @Column(name = "no")
    private String no;
    
    @Basic(optional = false)
    @Column(name = "spec")
    private String spec;
    
    @Basic(optional = false)
    @Column(name = "price")
    private double price;
    
    @Column(name="series_id")
    private Integer seriesId;
    
    @Column(name="series_id2")
    private Integer seriesNameId;
    
    @JoinTable(name = "product_images", joinColumns = {@JoinColumn(name = "product_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "images_id", referencedColumnName = "id")})
    @OneToMany(cascade={CascadeType.ALL},fetch = FetchType.LAZY)
    @OrderBy("id asc")
    private Collection<Images> imagesCollection;
    
    @JoinColumn(name = "series_id", referencedColumnName = "id",updatable=false,insertable=false)
    @ManyToOne(fetch = FetchType.LAZY)
    private Series series;
    
    @JoinColumn(name = "series_id2", referencedColumnName = "id",updatable=false,insertable=false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Series seriesName;
    
    @Column(name = "online")
    private Short online;
    
    @Lob
    @Column(name = "detail")
    private String detail;
    
    @Column(name = "createdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdate;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getSpec() {
        return spec;
    }

    public void setSpec(String spec) {
        this.spec = spec;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Integer getSeriesId() {
		return seriesId;
	}

	public void setSeriesId(Integer seriesId) {
		this.seriesId = seriesId;
	}

	public Integer getSeriesNameId() {
		return seriesNameId;
	}

	public void setSeriesNameId(Integer seriesNameId) {
		this.seriesNameId = seriesNameId;
	}

	public Collection<Images> getImagesCollection() {
        return imagesCollection;
    }

    public void setImagesCollection(Collection<Images> imagesCollection) {
        this.imagesCollection = imagesCollection;
    }

    public Series getSeries() {
        return series;
    }

    public void setSeries(Series series) {
        this.series = series;
    }

    public Series getSeriesName() {
        return seriesName;
    }

    public void setSeriesName(Series seriesName) {
        this.seriesName = seriesName;
    }

    public Short getOnline() {
		return online;
	}

	public void setOnline(Short online) {
		this.online = online;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

}
